-- | Benchmark

module Bench (main) where

import qualified BsBB
import qualified BB
import Interlude
import qualified Test.BenchPress as BP

main :: IO ()
main = printf "                             CPU       Wall    Speedup\n" >>
  examples >>= mapM_ (\(l,i,a) -> do
    (BP.mean -> cpu, BP.mean -> wall) <- BP.benchmark i (return ()) (\_ -> return ()) (\_ -> a)
    printf "%20s: %10.1f %10.1f %10.1f\n" l cpu wall (cpu/wall) :: IO ()
    hFlush stdout)

examples :: IO [(String, Int, IO ())]
examples = mapM (\(i,e) -> do
  s <- readFile ("examples/" ++ e)
  return (e,i, writeStdIO $ (`seq` ()) . show <$>
    (BsBB.prepare (-1) s >>= BB.inf (BsBB.trm $ Just (0.00005::Double)) (-1))))
  [ (10, "booth")
  , (10, "camelback")
  , (10, "ferguson")
  , (10, "beale")
  , (10, "goldstein_price")
  , (10, "rosenbrock")
  , ( 1, "colville")
  , ( 1, "gamma_pt")
  ]
